/*
 * RoleCreatorView.fx
 *
 * Created on 2010-03-10, 12:45:26
 */

package testlogowowanie;
import javafx.scene.control.CheckBox;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextBox;
import javafx.scene.control.Button;
import java.lang.UnsupportedOperationException;
import java.lang.String;
import testlogowowanie.IRHelper;

/**
 * @author pgorzkowicz
 */

public class RoleCreatorView extends CustomNode,IRoleView{
    public var rh:IRHelper;

    public var possiblePermissions:String[] = ["permission1","permission2","permission3"]; // String?

    public var nameTB:TextBox = TextBox {
	text: "name..."
	columns: 12
	selectOnFocus: true
    }

    public var confirmButton:Button = Button {
	text: "create"
	action: function() {
                def selected = getSelectedPermissions();
                if(rh!=null){
                    rh.acceptRoleAttributes(nameTB.text,selected);
                }else{
                    println("-----");
                    println("brak obiektu IRHelper");
                    println("name: {nameTB.text} \n attributes: {selected}");
                }


		
	}
}


    public var checkBoxes:CheckBox[];

    function makeCheckBox(label:String):CheckBox{
        return CheckBox {
            text: label;
            selected: false
        }
    }

    function generateForm(){
        for(permission in possiblePermissions){
            insert makeCheckBox(permission) into checkBoxes;
        }
    }

    function getSelectedPermissions():String[]{
        var selected:String[];
        for(ch in checkBoxes){
            if(ch.selected){
                insert ch.text into selected;
            }
        }
        return selected;
    }

    override protected function create () : Node {
        generateForm();
        return VBox{
            content: [nameTB,checkBoxes,confirmButton];
        }
    }

    override public function setPossiblePermissions (arg0 : nativearray of String) : Void {
        possiblePermissions = arg0;
    }

    override public function setIRHelper (arg0 : IRHelper) : Void {
        rh = arg0;
    }


}
